package org.abacus.platform.database.impl;

import org.abacus.platform.data.DataSourceProviderFactoryJdbc;
import org.abacus.platform.data.FetchDatabase;
import org.abacus.platform.data.Store;
import org.abacus.platform.data.StoreHelper;
import org.abacus.platform.database.Column;
import org.abacus.platform.database.Database;
import org.abacus.platform.database.Table;
import org.junit.Test;

public class DatabaseHelperTest {
	@Test
	public void testCreateTable() {
		Database database = Database.getInstance();
		Table arg0 = database.prepareTable();
		arg0.setTableName("lcy_table");
		Column e = database.prepareColumn();
		e.setColumnName("id");
		e.setDataType("float");
		e.setDataLength(11);
		e.setDataScale(2);
		e.setNullable(false);
		e.setPrimaryKey(true);
		arg0.getColumns().add(e);

		e = database.prepareColumn();
		e.setColumnName("code");
		e.setDataType("varchar");
		e.setDataLength(11);
		e.setNullable(false);
		e.setPrimaryKey(true);
		arg0.getColumns().add(e);
		String table = DatabaseHelper.create(arg0);
		System.out.print(table);
	}

	@Test
	public void data() {
		Store store = new FetchDatabase(new DataSourceProvider(), "select  * from table_template");
		// Json j = new Json();
		// System.out.print(j.toJson(store).toString());
		System.out.print(store.getKeys());
		System.out.print(store.getKeysAlias());
		System.out.print(store.getStore());
	}

	@Test
	public void store() {
		StoreHelper storeHelper = new StoreHelper();
		storeHelper.setDataSourceProviderFactory(new DataSourceProviderFactoryJdbc());
		Store store = storeHelper.getStore("select  * from table_template");
		// Json j = new Json();
		// System.out.print(j.toJson(store).toString());
		System.out.print(store.getKeys());
		System.out.print(store.getKeysAlias());
		System.out.print(store.getStore());
	}
}
